package sg4c.frontend.command;

import java.io.IOException;
import sg4c.frontend.GraphicsContext;
import sg4c.protocol.DataInputProtocol;

public class DrawText implements GraphicsCommand {

    
    private final String text;
    private final int x;
    private final int y;

    private DrawText(int x, int y, String text) {
        this.x = x;
        this.y = y;
        this.text = text;
    }

    public void execute(GraphicsContext context) {
        if (!context.noFill()) {
            context.loadFillColor();
            context.getGraphics().drawString(text, x, y);
        }
    }
    public static Factory factory = new Factory() {

        public GraphicsCommand parse(DataInputProtocol in) throws IOException {
            String text = in.readString();
            int x = in.readInt();
            int y = in.readInt();
            return new DrawText(x, y, text);
        }
    };
}
